export const getLocal = (key) => {
  let value = localStorage.getItem(key) || "";
  if (value.includes("[") || value.includes("{")) {
    value = JSON.parse(value);
  }
  return value;
};

export const setLocal = (key, value) => {
  let valueStr = JSON.stringify(value);
  localStorage.setItem(key, valueStr);
};

export const getSession = (key) => {
  let value = sessionStorage.getItem(key) || "";
  return value;
};

export const setSession = (key, value) => {
  sessionStorage.setItem(key, value);
};

//set windows
window.getLocal = getLocal;
window.setLocal = getLocal;
window.getSession = getSession;
window.setSession = setSession;

export default {
  getLocal,
  setLocal,
  getSession,
  setSession,
};
